package com.qlk.test.odcinterface.rest;

import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import org.junit.Test;
import org.springframework.util.Assert;

import com.qlk.common.client.AbstractClient;
import com.qlk.common.utils.http.HttpClientUtil;
import com.qlk.common.utils.serialize.JsonHelper;
import com.qlk.common.utils.wrap.Wrapper;
import com.qlk.odcinterface.domain.PmsProductPromotionItem;
import com.qlk.odcinterface.sdk.api.request.OdcRequest;
import com.qlk.odcinterface.sdk.api.request.PmsProductPromotionRequest;
import com.qlk.test.odcinterface.rest.dto.PmsProductPromotion;
import com.qlk.test.odcinterface.rest.response.PmsProductPromotionResponse;
import com.qlk.test.odcinterface.rest.Urls;

/**
 * PmsProductPromotionResource单元测试
 * 
 * @author zhaoyanan
 * @version 2016-4-14 13:22:59
 * 
 */
public class PmsProductPromotionResourceTestCase extends AbstractClient {
    
   /* @Test*/
    public void testGetPmsProductPromotion() {
        String url= Urls.API_DOMAIN + "/pmsProductPromotion/getPmsProductPromotion";

        PmsProductPromotionRequest request = new PmsProductPromotionRequest();
//        request.setId(1l);
        PmsProductPromotionResponse response = super.getRestTemplate().postForObject(url, request, PmsProductPromotionResponse.class);
        Assert.notNull(response);
        PmsProductPromotion pmsProductPromotion = super.getResult(response);
        Assert.notNull(pmsProductPromotion);
    }
    
    @Test
    public void testsyncPmsProductPromotion() {
        String url= Urls.API_DOMAIN + "/pmsProductPromotion/syncPmsProductPromotion";
        PmsProductPromotionRequest promotionRequest = new PmsProductPromotionRequest();
        promotionRequest.setId(5);
        promotionRequest.setCode("1603110005");
        promotionRequest.setName("测试活动1");
        promotionRequest.setPromotionLanguage("单品促销测试促销语");
        promotionRequest.setChannel("1");
        promotionRequest.setStatus(30);
       
		/*try {
			//promotionRequest.setCreatedAt(new Date());
			SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
			promotionRequest.setDeletedAt(format.parse("2016-04-15 00:01:02"));
		} catch (ParseException e1) {
			// TODO Auto-generated catch block
			e1.printStackTrace();
		}*/
        
        List<PmsProductPromotionItem> pmsProductPromotionItemList = new ArrayList<PmsProductPromotionItem>();
        PmsProductPromotionItem pmsProductPromotionItem1 = new PmsProductPromotionItem();
        pmsProductPromotionItem1.setPromotionId(5);
        pmsProductPromotionItem1.setGoodsId(111);
        pmsProductPromotionItem1.setSkuId(503);
        pmsProductPromotionItem1.setProductChannel("B2C商城");
        pmsProductPromotionItem1.setPrice("62.00");
        PmsProductPromotionItem pmsProductPromotionItem2 = new PmsProductPromotionItem();
        pmsProductPromotionItem2.setPromotionId(5);
        pmsProductPromotionItem2.setGoodsId(121);
        pmsProductPromotionItem2.setSkuId(504);
        pmsProductPromotionItem2.setProductChannel("B2C商城");
        pmsProductPromotionItem1.setPrice("62.00");
        pmsProductPromotionItemList.add(pmsProductPromotionItem1);
        pmsProductPromotionItemList.add(pmsProductPromotionItem2);
        
        promotionRequest.setPromotionItemList(pmsProductPromotionItemList);
        
        Map<String, String> request = new HashMap<String, String>();
        request.put("isStatusUpdate","0");
        request.put("content", JsonHelper.toJson(promotionRequest));       

       String rs;
		try {
			rs = HttpClientUtil.postForObject(url, null, request);
			System.out.println(rs);
		} catch (Exception e) {
			e.printStackTrace();
		}
//        request.setId(1l);
      /* */
       /* PmsProductPromotion pmsProductPromotion = super.getResult(response);
        Assert.notNull(pmsProductPromotion);*/
    }
    
}
